package com.sskj.gocoin.mine;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;

import com.sskj.gocoin.R;
import com.sskj.gocoin.common.App;
import com.sskj.gocoin.common.adapter.BaseAdapter;
import com.sskj.gocoin.common.adapter.ViewHolder;
import com.sskj.gocoin.m.bean.Menu;
import com.sskj.gocoin.utils.ClickUtil;
import com.sskj.gocoin.v.activity.AboutUsActivity;
import com.sskj.gocoin.v.activity.AssetManageActivity;
import com.sskj.gocoin.v.activity.CashAddressListActivity;
import com.sskj.gocoin.v.activity.ExchangeActivity;
import com.sskj.gocoin.v.activity.GoogleSettingActivity;
import com.sskj.gocoin.v.activity.MainActivity;
import com.sskj.gocoin.v.activity.SecurityCenterActivity;
import com.sskj.gocoin.v.activity.ShareActivity;
import com.sskj.gocoin.v.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author Hey
 * Create at  2019/03/29
 */
public class MineFragment extends BaseFragment<MainActivity, MinePresenter> {

    @BindView(R.id.img_head)
    ImageView imgHead;
    @BindView(R.id.tv_account)
    TextView tvAccount;
    @BindView(R.id.tv_uid)
    TextView tvUid;
    @BindView(R.id.sign_img)
    ImageView signImg;
    @BindView(R.id.tv_asset)
    TextView tvAsset;
    @BindView(R.id.tv_asset_cny)
    TextView tvAssetCny;
    @BindView(R.id.notice_switch)
    TextView noticeSwitch;
    @BindView(R.id.menu)
    RecyclerView menuRecyclerView;

    BaseAdapter<Menu> menuAdapter;

    List<Menu> menuData = new ArrayList<>();

    @Override
    public int getLayoutId() {
        return R.layout.fragment_mine_n;
    }

    @Override
    public MinePresenter getPresenter() {
        return new MinePresenter();
    }

    @Override
    public void initView() {
        initMenu();
    }


    @Override
    public void initData() {

    }


    private void initMenu() {
        menuData.add(new Menu(App.INSTANCE.getString(R.string.strMineFragment204), R.mipmap.h_mine_security, SecurityCenterActivity.class));
        menuData.add(new Menu(App.INSTANCE.getString(R.string.strMineFragment205), R.mipmap.h_mine_asset_manager, AssetManagerActivity.class));
        menuData.add(new Menu(App.INSTANCE.getString(R.string.strMineFragment207), R.mipmap.h_mine_address, CashAddressListActivity.class));
        menuData.add(new Menu(App.INSTANCE.getString(R.string.exchange), R.mipmap.h_mine_exchange, ExchangeActivity.class));
        menuData.add(new Menu(getString(R.string.my_share), R.mipmap.h_mine_share, ShareActivity.class));
        menuData.add(new Menu(App.INSTANCE.getString(R.string.strMineFragment210), R.mipmap.h_mine_apply_seller, SecurityCenterActivity.class));
        menuData.add(new Menu(getString(R.string.apply_market_seller), R.mipmap.h_mine_apply_market_seller, SecurityCenterActivity.class));
        menuData.add(new Menu(App.INSTANCE.getString(R.string.strMineFragment211), R.mipmap.h_mine_about, AboutUsActivity.class));
        menuData.add(new Menu(App.INSTANCE.getString(R.string.xmlactivity_google_setting20), R.mipmap.h_mine_setting, GoogleSettingActivity.class));  // 设置
        menuRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 3));
        menuAdapter = new BaseAdapter<Menu>(R.layout.item_main_menu, menuData, menuRecyclerView) {
            @Override
            public void bind(ViewHolder holder, Menu item) {
                holder.setText(R.id.menu_title, item.getText());
                holder.setImageResource(R.id.menu_icon, item.getIcon());
                if ((holder.getAdapterPosition() + 1) % 3 == 0 && holder.getAdapterPosition() != 0) {
                    holder.setVisible(R.id.menu_right_line, false);
                } else {
                    holder.setVisible(R.id.menu_right_line, true);
                }
                if (menuData.size() % 3 == 0) {
                    if (holder.getAdapterPosition() + 1 > 3 * (menuData.size() / 3 - 1)) {
                        holder.setVisible(R.id.menu_bottom_line, true);
                    } else {
                        holder.setVisible(R.id.menu_bottom_line, true);
                    }
                } else {
                    if ((holder.getAdapterPosition() + 1) > (menuData.size() - menuData.size() % 3)) {
                        holder.setVisible(R.id.menu_bottom_line, true);
                    } else {
                        holder.setVisible(R.id.menu_bottom_line, true);
                    }
                }
                ClickUtil.click(holder.getView(R.id.menu_item), () -> {
                    Intent intent = new Intent(getContext(), item.getClz());
                    startActivity(intent);
                });
            }
        };
    }

    public static MineFragment newInstance() {
        MineFragment fragment = new MineFragment();
        Bundle bundle = new Bundle();
        fragment.setArguments(bundle);
        return fragment;
    }


}
